package com.szt.ynb.server.router.interceptor;

import java.io.IOException;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.szt.ynb.server.router.common.SessionConst;

public class ManageInteceptor extends HandlerInterceptorAdapter {
	private String loginUrl = "/manage/main/login";
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		if (request.getSession().getAttribute(SessionConst.SESSION_ADMIN) == null) {
			toLogin(response);
			return false;
		}
		return true;
	}
	
	private void toLogin(ServletResponse response) throws IOException {
		((HttpServletResponse) response).sendRedirect(loginUrl);
	}
}
